#ifndef FLASH_H
#define FLASH_H

#include "stm32f4xx_hal.h"

#define FLASH_WAITETIME 0xffff

#define STM32_FLASH_BASE 0x08000000 // FLASH的起始地址
#define FLASH_SAVE_ADDR 0X08020000  //存放起始地址，可自己改

// FLASH 扇区的起始地址
#define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000)  //扇区0起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000)  //扇区1起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000)  //扇区2起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000)  //扇区3起始地址, 16 Kbytes
#define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000)  //扇区4起始地址, 64 Kbytes
#define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000)  //扇区5起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000)  //扇区6起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000)  //扇区7起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000)  //扇区8起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000)  //扇区9起始地址, 128 Kbytes
#define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) //扇区10起始地址,128 Kbytes
#define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) //扇区11起始地址,128 Kbytes

#define FLASH_Sector_0 0
#define FLASH_Sector_1 1
#define FLASH_Sector_2 2
#define FLASH_Sector_3 3
#define FLASH_Sector_4 4
#define FLASH_Sector_5 5
#define FLASH_Sector_6 6
#define FLASH_Sector_7 7
#define FLASH_Sector_8 8
#define FLASH_Sector_9 9
#define FLASH_Sector_10 10
#define FLASH_Sector_11 11

extern uint32_t TEXT_Buffer[];
#define TEXT_LENTH 4 //数组长度
#define SIZE 4

// typedef struct
// {
//     float GAIT_S;
//     float GAIT_H;
//     float GAIT_T;

//     float gait_delta_x;
//     float gait_delta_z;

//     float delta_h;
//     float delta_z;
//     float delta_x;
//     float delta_t;
//     float delta_dh[4];

// } Flash_Data;
#define DOG_FLASH_DATA_NUM 15
extern float dog_flash_data[DOG_FLASH_DATA_NUM];

uint32_t STMFLASH_ReadWord(uint32_t faddr);
uint16_t STMFLASH_GetFlashSector(uint32_t addr);
void STMFLASH_Write(uint32_t WriteAddr, uint32_t *pBuffer, uint32_t NumToWrite);
void STMFLASH_Read(uint32_t ReadAddr, uint32_t *pBuffer, uint32_t NumToRead);

#endif // FLASH_H